

package com.hazelcast.internal.util;

import java.util.Iterator;

public class FlatCompositeIterator<E> extends AbstractCompositeIterator<E> {

    private final Iterator<Iterator<E>> iterators;

    public FlatCompositeIterator(Iterator<Iterator<E>> iterators) {
        this.iterators = iterators;
    }

    @Override
    protected Iterator<E> nextIterator() {
        while (iterators.hasNext()) {
            Iterator<E> iterator = iterators.next();

            if (iterator.hasNext()) {
                return iterator;
            }
        }

        return null;
    }
}
